package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.DataCenterService;
import com.yixun.qfbao.apidto.GetCustomerConversionPageReqDto;
import com.yixun.qfbao.apidto.GetCustomerConversionPageResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.GetCustomerConversionPageReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author guifang.weng
 * @create 2017-11-27 16:23
 **/
@Service
public class GetCustomerConversionPageHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetCustomerConversionPageHander.class);

    @Autowired
    private DataCenterService dataCenterService;
    @Autowired
    private LoginUtils loginUtils;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetCustomerConversionPageResDto> res = new BaseResponseDTO<>();
        GetCustomerConversionPageReqVo reqVo = (GetCustomerConversionPageReqVo) reqDto;
        GetCustomerConversionPageReqDto getCustomerConversionPageReqDto = reqVo.getParams();
        PartnerInfo pi = loginUtils.getUser(getCustomerConversionPageReqDto.getUserId());
        if (pi == null) {
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("未获取到用户信息");
            return res;
        }
        getCustomerConversionPageReqDto.setMerchantId(pi.getHigherid());
        getCustomerConversionPageReqDto.setAccountType(pi.getAccountType());
        try {
            GetCustomerConversionPageResDto resDto = dataCenterService.getCustomerConversionPage(getCustomerConversionPageReqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (Exception e) {
            logger.error("GetCustomerConversionPageHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("查询信息失败");
        }
        return res;
    }
}
